/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.supinfo.youfood.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author Michael
 */
@Entity
@Table(name="menu")
public class Menu implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id_menu")
    private Long id_menu;
    
    @NotEmpty
    private String nom;
    
    @NotEmpty
    private String description;

    @NotNull
    private double prix;
    
    @NotNull
    private int actif;
    
    @ManyToMany(fetch= FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    @JoinTable(name="menu_produit")
    private List<Produit> produits;
    
    @OneToMany(mappedBy = "platDuJour",fetch= FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    private List<Restaurant> restaurants;
    
    @ManyToMany(fetch= FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    @JoinTable(name="restaurants_menus")
    private List<Restaurant> dansRestaurants;

    public Menu() {
    }

    public Long getId_menu() {
        return id_menu;
    }

    public void setId_menu(Long id_menu) {
        this.id_menu = id_menu;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public double getPrix() {
        return prix;
    }

    public void setPrix(double prix) {
        this.prix = prix;
    }

    public List<Produit> getProduits() {
        return produits;
    }

    public void setProduits(List<Produit> produits) {
        this.produits = produits;
    }

    public List<Restaurant> getRestaurants() {
        return restaurants;
    }

    public void setRestaurants(List<Restaurant> restaurants) {
        this.restaurants = restaurants;
    }

    public int getActif() {
        return actif;
    }

    public void setActif(int actif) {
        this.actif = actif;
    }

    public List<Restaurant> getDansRestaurants() {
        return dansRestaurants;
    }

    public void setDansRestaurants(List<Restaurant> dansRestaurants) {
        this.dansRestaurants = dansRestaurants;
    }
    
    public void addRestaurant(Restaurant resto)
    {
        if(dansRestaurants == null)
        {
            dansRestaurants = new ArrayList();
        }
        if(!dansRestaurants.contains(resto))
        {
            this.dansRestaurants.add(resto);
        }
    }
    
    public void removeRestaurant(Restaurant resto)
    {
        if(dansRestaurants.contains(resto))
        {
            this.dansRestaurants.remove(resto);
        }
    }
    
    public void removeAllRestaurant()
    {
        this.dansRestaurants = null;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Menu other = (Menu) obj;
        if (this.id_menu != other.id_menu && (this.id_menu == null || !this.id_menu.equals(other.id_menu))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        return hash;
    }
    
}
